package com.github.niefy.modules.wx.manage;

import com.alibaba.fastjson.JSONObject;
import com.github.niefy.modules.wx.entity.ChangduUserRecharge;
import com.github.niefy.modules.wx.entity.WeiboCallMe;
import com.github.niefy.modules.wx.service.impl.WeiBoServiceImpl;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;

@RestController
@Slf4j
public class WeiBoManageController {

    @Autowired
    private WeiBoServiceImpl weiBoManage;

    @RequestMapping("/weiBo/wb_JianCeLianJie_CallWeiBo_guang_zhu")
    public void wb_JianCeLianJie_CallWeiBo_guang_zhu() {
        weiBoManage.wb_JianCeLianJie_CallWeiBo_guang_zhu();
    }

    @RequestMapping("/weiBo/test_wb_JianCeLianJie_CallWeiBo_fu_fei")
    public void test_wb_JianCeLianJie_CallWeiBo_fu_fei() {
        weiBoManage.test_wb_JianCeLianJie_CallWeiBo_fu_fei();
    }

    @RequestMapping("/weiBo/wb_JianCeLianJie_CallWeiBo_fu_fei")
    public void wb_JianCeLianJie_CallWeiBo_fu_fei() {
        ChangduUserRecharge changduUserRecharge = new ChangduUserRecharge();
        changduUserRecharge.setPayFee(BigDecimal.valueOf(4900.00));
        // 61.242.152.184 changdu  =  27.24.44.32
        changduUserRecharge.setIp("183.9.197.18");
        weiBoManage.wb_JianCeLianJie_CallWeiBo_fu_fei(Lists.newArrayList(changduUserRecharge));
    }

    @GetMapping("/wb/callMe")
    @ApiOperation(value = "列表")
    public JSONObject callMe(WbCallMe wbCallMe) {

        System.out.println("/wb/callMe 1 = " + com.alibaba.fastjson2.JSON.toJSONString(wbCallMe));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", "OK");
        jsonObject.put("Code", "0");

        try {
            weiBoManage.wb_JianCeLianJie_CallMe(wbCallMe);
        } catch (Exception e) {
            log.error("callMe ", e);
            jsonObject.put("result", "Error");
            jsonObject.put("Code", "10000");
        }
        System.out.println("/wb/callMe 2 = " + jsonObject);
        return jsonObject;
    }

    @Getter
    @Setter
    public static class WbCallMe {
        private String campaignid;
        private String ip;
        private String ua;
        private String clicktime;
        private String IMP;
        private String ad_id;


        public WeiboCallMe toWeiboCallMe() {
            WeiboCallMe result = new WeiboCallMe();
            result.setIp(this.getIp());
            result.setUa(this.getUa());
            result.setCampaignid(this.getCampaignid());
            result.setImp(this.getIMP());
            result.setClicktime(this.getClicktime());
            result.setAdId(this.getAd_id());
            return result;
        }
    }
}
